<template>
  <div>
      <el-form ref="form" :rules="rules" :model="form" label-width="auto">
          <el-form-item  label="性别" prop="sex">
              <el-select v-model="form.sex" ref="sex">
                  <el-option label="男" value="1"></el-option>
                  <el-option label="女" value="0"></el-option>
              </el-select>
          </el-form-item>
      </el-form>
  </div>
</template>

<script>
module.exports = {
    watch: {
        '$root.s_store.sex': {
            immediate: true,
            handler(val) {
                this.form.sex = val
            }
        },
        form: {
            deep: true,
            handler(val) {
                this.$emit('change', val)
            }
        }
    },
    data() {
        return {
            form: {
                sex: ''
            },
            rules: {
                sex: [
                    { required: true, message: '请选择性别', trigger: 'blur' }
                ]
            }
        }
    },
    methods: {
        valid() {
            let result = false;
            this.$refs["form"].validate((valid, object) => {
                result = valid;
                let keys = Object.keys(object ?? {});
                if (keys.length > 0) {
                    this.$scrollCenter(this.$refs[keys[0]].$el)
                }

            })
            return result;
        }
    }
}
</script>

<style scoped>

</style>
